package com.sharkburner.aeris.ui.module.appHeader.composition;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sharkburner.aeris.bean.MessageResource;
import com.sharkburner.aeris.service.AuthenticationManager;
import com.sharkburner.aeris.ui.module.appMenu.composition.AppMenuLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;

/**
 * @author adarie
 * 
 */
@Component
public class AppHeaderLayout extends VerticalLayout {

    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;
    private GridLayout appHeaderLayout;
    @Autowired
    private AppMenuLayout mainMenu;
    @Autowired
    private transient AuthenticationManager authManager;

    @Autowired
    protected transient MessageResource messageResource;

    @PostConstruct
    public void init() {
	setWidth("100.0%");
	setHeight("100px");
	buildMainLayout();
    }

    @SuppressWarnings("deprecation")
    private void buildMainLayout() {
	addComponent(mainMenu);
	appHeaderLayout = new GridLayout(4, 1);
	appHeaderLayout.setWidth("100%");
	appHeaderLayout.setMargin(true);

	/*
	 * Application Name Composition
	 */
	VerticalLayout appNameComposition = new VerticalLayout();

	Label appNameLabel = new Label("Aeris");
	appNameLabel.setStyle(Reindeer.LABEL_H2);
	appNameComposition.addComponent(appNameLabel);

	Label appDescriptionLabel = new Label("Monitoring Application");
	appDescriptionLabel.setStyle(Reindeer.LABEL_SMALL);
	appNameComposition.addComponent(appDescriptionLabel);

	appHeaderLayout.addComponent(appNameComposition, 0, 0);
	appHeaderLayout.setComponentAlignment(appNameComposition,
		Alignment.MIDDLE_LEFT);

	/*
	 * Application Control Panel Composition
	 */
	GridLayout appUserControlPanel = new GridLayout(2, 1);
	appUserControlPanel.setSpacing(true);

	Button helpButton = new Button("Help");
	helpButton.setStyle(Reindeer.BUTTON_SMALL);
	appUserControlPanel.addComponent(helpButton, 0, 0);

	Button logoutButton = new Button("Logout");
	logoutButton.setStyle(Reindeer.BUTTON_SMALL);
	appUserControlPanel.addComponent(logoutButton, 1, 0);

	appHeaderLayout.addComponent(appUserControlPanel, 3, 0);
	appHeaderLayout.setComponentAlignment(appUserControlPanel,
		Alignment.MIDDLE_RIGHT);

	addComponent(appHeaderLayout);
    }
}
